﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace StudentMaragement.Models
{
    public class MockStudentRepository : IStudentRepository
    {
        private List<Student> _studentList;

        //创建学生信息-模拟数据库
        public MockStudentRepository()
        {
            _studentList = new List<Student>()
            {
                new Student(){Id=1,Name="怪咖", ClassName=ClassNameEnum.FirstGrade,Email="12454545@qq.com"},
                new Student(){Id=2,Name="丑八怪",ClassName=ClassNameEnum.SecondGrade,Email="12454545@qq.com"},
                new Student(){Id=3,Name="演员",ClassName=ClassNameEnum.GradeThree,Email="12454545@qq.com"}
            };
        }

        //添加数据
        public Student Add(Student student) {
            student.Id = _studentList.Max(s => s.Id) + 1;
            _studentList.Add(student);
            return student;
        }

        //查询全部
        public IEnumerable<Student> GetAllStudents()
        {
            return _studentList;
        }

        //查询单个
        public Student GetStudent(int id)
        {
            return _studentList.FirstOrDefault(a => a.Id == id);
        }



    }
}
